package info.maxhis.bn.birthday;

import info.maxhis.bn.R;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class FriendListAdapter extends BaseAdapter {
	
	private List<Map<String, Object>> data;
	private Context context;
	
	
	
	public FriendListAdapter(List<Map<String, Object>> data, Context context) {
		super();
		this.data = data;
		this.context = context;
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder ;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.birthday_list_item, null);
            viewHolder = new ViewHolder();
            viewHolder.image = (ImageView) convertView.findViewById(R.id.profile_img);
            viewHolder.name = (TextView) convertView.findViewById(R.id.name);
            viewHolder.birthday = (TextView) convertView.findViewById(R.id.date);
            viewHolder.daysleft = (TextView) convertView.findViewById(R.id.days_left);
            viewHolder.id = (TextView) convertView.findViewById(R.id.friend_id);
            viewHolder.age = (TextView) convertView.findViewById(R.id.age);
            
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        
        Map<String, Object> friend = this.data.get(position);
        viewHolder.image.setImageBitmap((Bitmap)friend.get("profile"));
        viewHolder.name.setText((String) friend.get("name"));
        viewHolder.birthday.setText((String)friend.get("birthday"));
        viewHolder.daysleft.setText((String)friend.get("leftdays"));
        viewHolder.id.setText("" + friend.get("id"));
        viewHolder.age.setText("" + friend.get("age"));
		return convertView;
	}

	static class ViewHolder {

        ImageView image;
        TextView name;
        TextView birthday;
        TextView uid;
        TextView id;
        TextView daysleft;
        TextView age;
        
    }
}

